#include "CDTimeManager.h"
#include "UnityCode.h"

using namespace std;


void CDTimeManager::UpdatePauseTime()
{
	if(SubTime > 0)
	{		
		std::map<int,CCDTime*>::iterator it = m_CDTimeList.begin();
		for(; it!=m_CDTimeList.end(); it++)
		{
			CCDTime * pTime = it->second;
			if(pTime != NULL)
				pTime->FixLastPauseTime(SubTime);

		}

	}

}

CDTimeManager::CDTimeManager()
{
	SubTime = 0;
	PauseEndTime =0;
	PauseStartTime = 0;
	dwCount = 0;
}

void CDTimeManager::CalcSubTime()
{
	PauseEndTime = millisecondNow();
	SubTime = PauseEndTime - PauseStartTime;
	UpdatePauseTime();
}

int CDTimeManager::AddTime( CCDTime * pTimer )
{
	dwCount++;
	m_CDTimeList.insert(make_pair(dwCount,pTimer));
	return dwCount;
	
}

void CDTimeManager::DeleteTime( CCDTime * pTimer )
{
	std::map<int,CCDTime*>::iterator it = m_CDTimeList.find(pTimer->ID());
	if(it != m_CDTimeList.end())
	{
		m_CDTimeList.erase(it);
	}
}
